export function go (url, $router) {
	const useRouter = typeof url === 'object' || ($router && typeof url === 'string' && !/http/.test(url))
	if (useRouter) {
		if (typeof url === 'object' && url.replace === true) {
			$router.replace(url)
		} else {
			url === 'BACK' ? $router.go(-1) : $router.push(url)
		}
	} else {
		window.location.href = url
	}
}

export function getUrl (url, $router) {
	// Make sure the href is right in hash mode
	if ($router && !$router._history && typeof url === 'string' && !/http/.test(url)) {
		return '#!' + url
	}
	return url && typeof url !== 'object' ? url : 'javascript:void(0);'
}

export function goBlank (routerPath, $router) {
	if ($router) {
		let routeData = {}
		if (typeof routerPath === 'string') {
			routeData = $router.resolve(routerPath)
		} else {
			const { path, query } = routerPath
			routeData = $router.resolve({ path, query })
		}
		window.open(routeData.href, '_blank')
	} else {
		window.open(routerPath, '_blank')
	}
}
